<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.fckeditor.net" prefix="FCK" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<%@page import="database.*"%>
<%@ page import="java.io.BufferedReader" %>
<%@ page import="java.io.FileReader" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>编辑文章-清风品道</title>
<script type="text/javascript">
	function FCKeditor_OnComplete(editorInstance) {
		//window.status = editorInstance.Description;
	}
</script>
</head>
<body>
<jsp:include page="./nav.jsp"></jsp:include>

<%
		String permission = (String)session.getAttribute("permission");
	%>
	<%
		if(permission == null || !permission.equals("a")) {
	%>
	<p style="color:red">您没有权限</p>
	<% } else { %>
	<%
	request.setCharacterEncoding("utf-8");
	int articleID = Integer.parseInt(request.getParameter("articleID"));
	Article article = DatabaseManager.articleQueryByArticleID(articleID);
	if(article != null) {
	%>
	<form action="EditArticleServlet" method="post">
		<input type="hidden" name="articleID" id="articleID" value="<%=articleID %>" />
		<table align="center">
			<caption>编辑文章</caption>
			<tr>
				<td align="right"><label>标题</label></td>
				<td align="left"><input type="text" id="title" name="title" value="<%=article.getTitle() %>" /></td>
			</tr>
			<%
				StringBuffer sb = new StringBuffer();
				BufferedReader in = new BufferedReader(new FileReader(application.getRealPath("/")+"/file/"+articleID));
				String line = null;
				while((line = in.readLine()) != null) {
					sb.append(line);
				}
			%>
			<tr valign="top">
				<td align="right"><label>正文</label></td>
				<td align="left"><FCK:editor instanceName="content" width="700px" height="500px" value="<%=new String(sb) %>"></FCK:editor></td>
			</tr>
			<tr>
				<td></td>
				<td align="left"><input type="submit" value="保存" /></td>
			</tr>
		</table>
	</form>
	<% }} %>
	<jsp:include page="./bottom.jsp"></jsp:include>
</body>
</html>